﻿using Ledict.ConditionExtract.BLL;
using Ledict.ConditionExtract.Model;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Ledict.ConditionExtract
{
    public partial class NodeTree_AddArgumentType : Form
    {
        public NodeTree_AddArgumentType()
        {
            InitializeComponent();
        }

        public string AT_ID = "";
        public string AT_CauseID = "";
        public string AT_Code = "";
        public string AT_Name = "";
        public string AT_MatchKeyWord = "";
        public string CC_ID = "";
        NodeTree_ArgumentTypeBLL nodetree_argumenttypebll = new NodeTree_ArgumentTypeBLL();
        NewIDBLL newidbll = new NewIDBLL();

        /// <summary>
        /// 初始化
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void NodeTree_AddArgumentType_Load(object sender, EventArgs e)
        {
            if (AT_ID != "")//修改
            {
                AT_CodeText.Text = AT_Code;
                AT_NameText.Text = AT_Name;
                AT_MatchKeyWordText.Text = AT_MatchKeyWord.Replace(";", ";\n").Replace("；", "；\n");
                AT_CodeText.Enabled = false;

            }
            else
            {
                AT_CodeText.Enabled = true;
            }
            if (AT_CauseID == "")
                NotCauseID.Checked = true;
            else
                ISCauseID.Checked = true;
        }

        /// <summary>
        /// 保存
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>

        private void Save_Click(object sender, EventArgs e)
        {
            try
            {
                SYS_ArgumentType Model = new SYS_ArgumentType();
                Model.AT_CauseID = AT_CauseID;
                if (string.IsNullOrEmpty(AT_CodeText.Text))
                {
                    MessageBox.Show("请填写字典编号后再试！");
                    return;
                }
                if (string.IsNullOrEmpty(AT_NameText.Text))
                {
                    MessageBox.Show("请填写字典名称后再试！");
                    return;
                }
                if (string.IsNullOrEmpty(AT_MatchKeyWordText.Text))
                {
                    MessageBox.Show("请填写字典值后再试！");
                    return;
                }
                if (AT_ID == "")//新加
                {
                    Model.AT_ID = newidbll.JudgeDoc_CreateID("SYS_ArgumentType");
                    Model.AT_Code = AT_CodeText.Text;
                    Model.AT_Name = AT_NameText.Text;
                    Model.AT_MatchKeyWord = AT_MatchKeyWordText.Text;
                    Model.AT_ShowIndex = nodetree_argumenttypebll.GetAT_ShowIndex();
                    if (nodetree_argumenttypebll.Exists(Model) != "")
                    {
                        MessageBox.Show("在当前级别内,编号也存在，请重新命名！");
                        return;
                    }
                    else
                        nodetree_argumenttypebll.Add(Model);
                }
                else //修改
                {
                    Model.AT_ID = AT_ID;
                    Model.AT_Code = AT_Code;
                    Model.AT_Name = AT_NameText.Text;
                    Model.AT_MatchKeyWord = AT_MatchKeyWordText.Text;
                    nodetree_argumenttypebll.Update(Model, this.CC_ID);
                }
                MessageBox.Show("保存成功！");
                //NodeTree nodetree = NodeTree.Instance;
                //nodetree.ShowArgumentType();
                //NodeTree1 nodetree1 = NodeTree1.Instance;
                //nodetree1.ShowArgumentType();
                this.Close();
            }
            catch (Exception error)
            {
                MessageBox.Show("保存失败！" + error);
            }
        }

        private void ISCauseID_Click(object sender, EventArgs e)
        {
            AT_CauseID = CC_ID;
        }

        private void NotCauseID_Click(object sender, EventArgs e)
        {
            AT_CauseID = "";
        }



    }
}
